package com.pigdogbay.androidutils.mvp;

import java.util.Date;

public class AdPresenter {
	
	//2 Days Ad Free
	public static final long AD_FREE_GRACE_PERIOD_IN_MILLIS = 2L*24L*60L*60L*1000L;

	
	private IAdView _View;
	private IAdModel _Model;
	public void setView(IAdView view){_View = view;}
	public void setModel(IAdModel model){_Model = model;}
	
	public AdPresenter(){}
	public AdPresenter(IAdView view, IAdModel model)
	{
		_View = view;
		_Model = model;
	}
	
	public void adCheck()
	{
		if (getRemoveAd())
		{
			_View.removeAd();
		}
		else
		{
			_View.showAd();
		}
	}
	
	private boolean getRemoveAd()
	{
		long purchaseTime = _Model.getPurchaseDate();
		long timeNow = new Date().getTime();
		if (purchaseTime==0)
		{
			purchaseTime = timeNow;
			_Model.setPurchaseDate(purchaseTime);
		}
		long timeElapsedSincePurchase = timeNow-purchaseTime;
		if (timeElapsedSincePurchase<_Model.getGracePeriod())
		{
			return true;
		}
		return _Model.getDisableAds();
	}
}
